
<?php include_once(dirname(__FILE__) . '/../general/head.php'); ?>

<!-- header -->
<?php include_once(dirname(__FILE__) . '/../general/header.php'); ?>

<?php include_once('left.php'); ?>


<div id="page-wrapper">

    <div class="row">
        <div class="col-lg-12">
            <h1 class="page-header">Calibration</h1>
        </div>
    </div>

    <?php
    if ($addResult) {
        ?>
        <div class="row">
            <div class="col-lg-12">
                <div class="panel panel-success">
                    <div class="panel-heading">
                        <?php echo $addResult; ?>
                    </div>
                </div>
            </div>
        </div>
    <?php } ?>

    <div class="row">
        <div class="col-lg-12">
            <div class="panel panel-default">
                <!--        <div class="panel-heading">
                            Thông tin
                        </div>-->
                <div class="panel-body">
                    <div class="row">
                        <!--Cột trái-->
                        <div class="col-lg-12">
                            <div class="form-group">
                                <label>Đợt đánh giá</label>
                                <input type="text" name="name" class="form-control" style="width: 50%;" readonly="readonly" value="<?php echo $evaluation['name']; ?>" />
                            </div>

                            <label>Thông tin nhân viên</label>
                            <table class="table table-striped table-hover table-bordered">
                                <tr>
                                    <td>Code</td>
                                    <td><?php echo $editUser['code']; ?></td>
                                    <td>Location</td>
                                    <td><?php echo $editUser['location']; ?></td>
                                </tr>
                                <tr>
                                    <td>Name</td>
                                    <td><?php echo $editUser['name']; ?></td>
                                    <td>Team leader</td>
                                    <td><?php echo $editUser['teamleaderInfo']['name']; ?></td>
                                </tr>
                                <tr>
                                    <td>Position</td>
                                    <td><?php echo show_human_title($editUser['title']); ?></td>
                                    <td>Supervisor</td>
                                    <td><?php echo $editUser['supervisorInfo']['name']; ?></td>
                                </tr>
                                <tr>
                                    <td>Email</td>
                                    <td><?php echo $editUser['email']; ?></td>
                                    <td>RSM</td>
                                    <td><?php echo $editUser['rsmInfo']['name']; ?></td>
                                </tr>
                                <tr>
                                    <td>Date started</td>
                                    <td><?php echo $editUser['starting_day']; ?></td>
                                    <td>Status</td>
                                    <td><?php echo $editUser['status']; ?></td>
                                </tr>
                            </table>


                        </div>
                    </div>

                </div>
            </div>
        </div>
    </div>

    <div class="row">
        <div class="col-lg-12">
            <div class="panel panel-default">
                <div class="panel-heading">
                    Performance
                </div>
                <div class="panel-body">
                    <div class="row">
                        <!--Cột trái-->
                        <div class="col-lg-6">
                            <table class="table table-striped table-hover table-bordered">
                                <tr>
                                    <td width="200px">Kết quả trắc nghiệm</td>
                                    <td><?php echo $editUser['testResult'] != false ? $editUser['testResult']['percentage'] . '%' : ''; ?></td>
                                </tr>
                                <tr>
                                    <td>Sales Performance</td>
                                    <td><?php echo $editUser['saleResult'] != false ? $editUser['saleResult']['score'] . '%' : ''; ?></td>
                                </tr>
                                <tr>
                                    <td>Kết quả ban đầu</td>
                                    <td><?php echo color_final_results($editUser['firstRating']['name']); ?></td>
                                </tr>
                                <tr>
                                    <td>Kết quả đánh giá thái độ</td>
                                    <td><?php echo $editUser['attResult']['rating']; ?></td>
                                </tr>
                                <tr>
                                    <td>Kết quả cuối cùng</td>
                                    <td><?php echo color_final_results($editUser['finalRating']['name']); ?></td>
                                </tr>
                            </table>

                        </div>
                    </div>

                </div>
            </div>
        </div>
    </div>

    <div class="row">
        <div class="col-lg-6">
            <div class="panel panel-default">
                <div class="panel-heading">
                    Điều chỉnh kết quả cuối cùng
                </div>
                <div class="panel-body">
                    <form method="post" action="<?php echo site_url(get_folder($loggedUser['title']) . '/calibrations/edit/' . $editUser['code'] . '/' . $evaluation['id']); ?>">
                        <input type="hidden" name="Command" value="Edit" />
                        <div class="form-group">
                            <label>Kết quả cuối cùng</label>
                            <select class="form-control normal-width <?php echo strtolower(str_replace(' ', '', $calibration['final_result'])); ?>" name="final_rating">
                                <?php foreach ($ratings as $eachRating) { ?>
                                    <option value="<?php echo $eachRating; ?>" class="<?php echo strtolower(str_replace(' ', '', $eachRating)); ?>" <?php echo ($eachRating == $calibration['final_result']) ? 'selected="selected"' : ''; ?>><?php echo $eachRating; ?></option>
                                <?php } ?>
                            </select>
                        </div>

                        <input type="hidden" />
                        <input type="submit" class="btn btn-primary" value="Submit" />
                        &nbsp;&nbsp;&nbsp;
                        <a href="<?php echo site_url(get_folder($loggedUser['title']) . '/calibrations'); ?>">Quay lại danh sách</a><br/><br/>
                        <?php if (isset($message) && $message != '') { ?>
                            <div class="alert alert-<?php echo $messageType; ?> alert-dismissable">
                                <button type="button" class="close" data-dismiss="alert" aria-hidden="true">×</button>
                                <?php echo $message; ?>
                            </div>
                        <?php } ?>
                    </form>
                </div>
            </div>
        </div>
    </div>


</div>
<!-- /#page-wrapper -->
<script>
    function check_cmt()
    {
        var ok = true;
        $('[name^=cmt]').each(function(index) {
            if ($(this).val() == '')
            {
                if ($('[id^=max]:eq(' + index + ')').is(':checked') || $('[id^=min]:eq(' + index + ')').is(':checked'))
                {
                    if ($(this).siblings().length == 0)
                    {
                        $(this).after('<label class="control-label" for="inputError" style="margin-bottom: auto;">Yêu cầu viết nhận xét</label>');

                    }
                    ok = false;
                }
            }
            else
            {
                $(this).siblings().remove();
            }
        });


        if (ok == false)
        {
            return false;
        }
        else
        {
            return true;
        }
    }


    $(document).ready(function() {
        var previous;

        $("select[name=final_rating]").one('focus', function() {
            // Store the current value on focus and on change
            previous = this.value;
        }).change(function() {
            // Do something with the previous value after the change
            //alert(previous);
            //
            
            var current = $('select[name=final_rating]').val();
            $('select[name=final_rating]').removeClass(previous.toLowerCase().replace(' ', ''));
            $('select[name=final_rating]').addClass(current.toLowerCase().replace(' ', ''));

            // Make sure the previous value is updated
            previous = this.value;
            
            
            
        });
    });

</script>

<?php include_once(dirname(__FILE__) . '/../general/footer.php'); ?>